/*************************
查看
* */
<template>
  <div>
    <el-dialog
      title="查看"
      :close-on-click-modal="true"
      :visible.sync="visible"
      top="8vh"
      width="70%"
      @close="closeDialog()"
    >
        <el-form ref="dataForm" :model="dataForm"  class="boxsty"   label-width="100px"  @keyup.enter.native="dataFormSubmit()"  >
          <el-form-item label="标题：" prop="sjbt">
            <span>{{dataForm.sjbt}}</span>
          </el-form-item>

          <el-form-item label="考核周期：" prop="khzq">
            <span>{{dataForm.khzq}}</span>
          </el-form-item>

          <el-form-item label="描述：" prop="sjdesc">
            <span>{{dataForm.sjdesc}}</span>
          </el-form-item>

          <el-form-item label="考核对象：">
                 <el-table
                  ref="multipleTable"
                  :data="khrNameList"
                  height="250"
                  style="width: 100%;"
                  tooltip-effect="dark"
                >
                  <el-table-column type="index"   width="70" align="center" label="序号" ></el-table-column>

                   <el-table-column
                     v-if="showRY"
                     prop="username"
                     label="员工编号" width="120" align="center"  show-overflow-tooltip>
                   </el-table-column>
                 <el-table-column
                   v-if="showRY"
                     prop="realname"
                     label="姓名" width="120" align="center"  show-overflow-tooltip>
                   </el-table-column>
                   <el-table-column
                     v-if="showRY"
                     prop="deptName"
                     label="部门" width="120" align="center"  show-overflow-tooltip>
                   </el-table-column>

                   <el-table-column
                     v-if="!showRY"
                     prop="deptName"
                     label="机构名称"
                     min-width="120" align="center"  show-overflow-tooltip>
                   </el-table-column>


                  <el-table-column
                    prop="lbms"
                    label="类别"  align="center"  width="120"show-overflow-tooltip >
                  </el-table-column>
                  <el-table-column
                    prop="yjms"
                    label="依据"  align="center"  width="120" show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="bz"
                    label="标准" align="center"   width="120" show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="zbgz"
                    label="指标规则" align="center"  width="120" show-overflow-tooltip>
                  </el-table-column>
                   <el-table-column
                     prop="jjx"
                     header-align="center"
                     width="120"
                     align="center"
                     label="奖金项"
                     show-overflow-tooltip
                   ></el-table-column>

                   <el-table-column
                     prop="jkjj"
                     header-align="center"
                     width="120"
                     align="center"
                     fixed="right"
                     label="加扣奖金"
                     show-overflow-tooltip
                   ></el-table-column>


                  <el-table-column
                    fixed="right"
                    prop="jkfz"
                    width="120"
                    label="加扣分值" align="center" >
                  </el-table-column>
                </el-table>

          </el-form-item>


        </el-form>

      <span slot="footer" class="dialog-footer">
<!--         <el-button type="primary" plain @click="closeDialog()">返回</el-button>-->
         <!--<el-button type="primary" plain @click="closeDialog()">确定</el-button>-->
          <div style="display: flex;justify-content: center">
             <el-button  @click="handleAgree(1)" type="primary" v-if="permissions.rckhsjkh_view_sub">同意</el-button>
             <el-button  @click="handleAgree(0)" type="danger"  v-if="permissions.rckhsjkh_view_sub">驳回</el-button>
          </div>
      </span>
    </el-dialog>
  </div>
</template>

<script>
    import { mapGetters} from "vuex";
    import {leaderAudition,showUserName,leaderAuditionRefuse,showRefuseUserName} from "@/api/dailyExamine/eventExamine/eventExamine.js";
    export default {
        data() {
            return {
                showRY:true,
                khrNameList: [],
                visible: false,
                dataForm: {},
                dataList:[],
                type:0// 0 驳回 1同意
            };
        },
        computed: {
           ...mapGetters(["permissions"])
        },
        watch: {},
            created() {
        },
        methods: {
            //初始化
            csh() {
                this.dataForm = {};
            },
            init(obj) {
                if (obj) {

                    this.dataList = this.dataList.push(obj) ;

                    this.dataForm = obj;
                    this.showRY = obj.khtype=='ry'?true:false;
                    this.khrNameList = obj.khdxList;

                    this.$nextTick(() => {
                        this.$refs.multipleTable.doLayout();
                    });
                }

                this.visible = true;
            },

            closeDialog() {
                this.visible = false;
                this.$emit("closeDialog");
            },
            handleChange(value) {
                console.log(value);
            },
            // 确定 同意/驳回
            confirmAgree() {

                let ids = this.dataForm.id ;

                if (this.type==1){
                    leaderAudition(ids.toString(), this.type).then(r => {
                        if (r.data.code == 0) {
                            this.$message.success("操作成功");
                            this.$emit("refreshDataList");
                            this.closeDialog();
                        } else {
                            this.$message.error(r.data.msg);
                        }
                    });
                }else{
                    leaderAuditionRefuse(ids.toString(), this.type).then(r => {
                        if (r.data.code == 0) {
                            this.$message.success("操作成功");
                            this.$emit("refreshDataList");
                            this.closeDialog();
                        } else {
                            this.$message.error(r.data.msg);
                        }
                    });
                }
            },

            // 同意/驳回
            handleAgree(type) {

                let that = this ;

                let ids = this.dataForm.id ;
                    if (type == 1) {
                        //同意
                        this.type = 1 ;
                        showUserName(ids.toString()).then(r => {
                            console.log(r.data);
                            this.getCryItem=r.data.msg;
                            const h = this.$createElement;
                            this.$msgbox({
                                title: '同意',
                                message: h('p', null, [
                                    h('span',  { style: 'font-size: 14px' },this.getCryItem.toString() ),
                                ]),
                                showCancelButton: true,
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                beforeClose: (action, instance, done) => {
                                    if (action === 'confirm') {
                                        //调用同意接口
                                        this.confirmAgree();
                                        done();
                                    } else {
                                        done();
                                    }
                                }
                            }).then(action => {
                            });
                        });
                    } else {
                        // 驳回
                        this.type = 0 ;
                        showRefuseUserName(ids.toString()).then(r => {
                            this.getCryItem=r.data.msg;
                            const h = this.$createElement;
                            this.$msgbox({
                                title: '驳回',
                                message: h('p', null, [
                                    h('span', { style: 'font-size: 16px' }, this.getCryItem.toString() ),
                                ]),
                                showCancelButton: true,
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                beforeClose: (action, instance, done) => {
                                    if (action === 'confirm') {
                                        this.confirmAgree() ;
                                        done();
                                    } else {
                                        done();
                                    }
                                }
                            }).then(action => {

                            });
                        })
                    }
            },
        }
    };
</script>
<style scoped>
  /deep/.boxsty{padding: 20px 30px!important;}
  /deep/.el-table th{padding: 5px!important;}

  .el-divider {
    background-color: #fff;
  }
  .tree-box {
    height: 500px;
    overflow: auto;
  }
</style>
